const express = require('express')
const app = express()

app.all("*", (req, res, next) => {
  res.header("Access-Control-Allow-Origin", req.headers.origin);
  res.header("Access-Control-Allow-Credentials", true);
  res.header("Referrer-Policy", 'no-referrer-when-downgrade');
  next();
});

app.get('/login', (req, res) => {
	res.cookie('user', 'jay', { maxAge: 20000000, httpOnly: true })
	res.json({ code: 0, message: "登陆成功" })
})

app.get('/user', (req, res) => {
	const user = req.headers.cookie.split("=")
	res.json({ code: 0, user })
})

app.post('/user/id', (req, res) => {
	const user = req.headers.cookie.split("=")
	res.json({ code: 0, user })
})

app.use('/static', express.static('public'))

app.listen("8000", () => {
	console.log("app1 running at port 8000")
})